﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NHibernateDB;

namespace WebCam
{
    public partial class VizualizarePacienti : Form
    {
        private string limba;

        public string CNP;

        public VizualizarePacienti(string limba)
        {
            InitializeComponent();
            Rename(limba);

            this.limba = limba;

            listaPacienti.View = View.Details;
            listaPacienti.FullRowSelect = true;
            listaPacienti.GridLines = false;

            string xmlFile = @"C:\Language" + limba + ".xml";
            XMLParser xmlParser = new XMLParser(xmlFile);
            List<string> namesForm = xmlParser.ExtractAttribute(listaPacienti.Name.ToString(), string.Empty, string.Empty, "name");

            foreach (string s in namesForm)
                listaPacienti.Columns.Add(s);


            PersistenceManager pm = PersistenceManager.Instance;
            IList<DateGeneralePacient> lista = pm.RetrieveAll<DateGeneralePacient>(SessionAction.BeginAndEnd);
            listaPacienti.Items.Clear();
            populateListView(lista);
        }

        private void populateListView(IList<DateGeneralePacient> list)
        {
            foreach (DateGeneralePacient dgp in list)
            {
                ListViewItem item = new ListViewItem(dgp.IdPacient);
                item.SubItems.Add(dgp.Nume);
                item.SubItems.Add(dgp.Prenume);
                item.SubItems.Add(dgp.Sex);
                item.SubItems.Add(dgp.DataNasterii.ToString());
                item.SubItems.Add(dgp.LoculNasterii);
                item.SubItems.Add(dgp.Resedinta);
                item.SubItems.Add(dgp.DomiciliuLegal);
                item.SubItems.Add(dgp.GrupaSanguina);
                item.SubItems.Add(dgp.Ocupatie);
                item.SubItems.Add(dgp.LocMunca);
                item.SubItems.Add(dgp.TalonPensie);
                listaPacienti.Items.Add(item);
            }
        }

        private void btSortareCNP_Click(object sender, EventArgs e)
        {
            PersistenceManager pm = PersistenceManager.Instance;
            IList<DateGeneralePacient> lista2 = pm.RetrieveEquals<DateGeneralePacient>("IdPacient", tbCNP.Text);
            listaPacienti.Items.Clear();
            populateListView(lista2);
        }

        private void btSelectarePacient_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listaPacienti.Items.Count; i++)
            {
                if (listaPacienti.Items[i].Selected == true)
                {
                    ListViewItem itm = listaPacienti.SelectedItems[0];
                    this.CNP = itm.SubItems[0].Text;
                    break;
                }
            }

            this.Hide();
        }
    }
}
